<template>
    <div>
        <div class="headstyle">
            <el-row :gutter="24">
            <el-col :span="8">
                <div class="grid-content bg-purple">
                <span class="locsty"><i class="el-icon-location iconsty"></i>当前位置：员工注册数据列表</span>
                </div>
            </el-col>
            <el-col :span="16">
                <div class="grid-content bg-purple">
                    <el-input  v-model="name" placeholder="请输入员工姓名" clearable class="selectsty"></el-input>
                    <el-input  v-model="phone" placeholder="请输入员工手机号码" clearable class="selectsty"></el-input>
                    <el-input  v-model="card" placeholder="请输入员工身份证号码" clearable class="selectsty"></el-input>                   
                    <el-button type="primary" @click="selectstudent">查询</el-button>
                </div>
            </el-col>           
            </el-row>
        </div>
        <div class="contentstyle">
             <el-table ref="multipleTable"  :data="tableData.filter(data=>total!=0)"  
                 tooltip-effect="dark" 
                 style="width: 100%;text-align:center"
                 border @selection-change="handleSelectionChange">
                <el-table-column type="selection"  width="55" align="center"></el-table-column>
                <el-table-column  prop="St_Name" label="员工姓名" show-overflow-tooltip align="center"> </el-table-column>
                <el-table-column  prop="St_Phone" label="员工手机号码" show-overflow-tooltip align="center"> 
                    <template slot-scope="scope">
                        <span>{{scope.row.St_Phone?scope.row.St_Phone.replace(/^(\d{4})\d+(\d{4})$/,"$1****$2"):""}}</span>
                    </template>
                </el-table-column>
                <el-table-column  prop="St_Card" label="员工身份证号码" show-overflow-tooltip align="center"> 
                    <template slot-scope="scope">
                        <span>{{scope.row.St_Phone?scope.row.St_Card.replace(/^(\d{4})\d+(\w{4})$/,"$1****$2"):""}}</span>
                    </template>
                </el-table-column>
                <el-table-column  prop="St_dateTime" label="员工注册时间" show-overflow-tooltip align="center"> </el-table-column>                       
                <el-table-column label="操作" align="center" width="200">
                    <template slot-scope="scope">
                       <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">Edit</el-button>                    
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
                    v-if = "paginationShow"
                    @current-change="currentChange"
                    @size-change="sizeChange"
                    :current-page="currentPage"
                    :page-size="pageSize"
                    layout="total, prev, pager, next, jumper"
                    :total="total"
            ></el-pagination>
        </div>
    </div>
</template>

<script>
export default {
  data() {
    return {
      //模板下载路径
      name: "",
      phone: "",
      card: "",
      pageSize: 10, // 页容量
      currentPage: 1, // 当前页
      total: 0, // 数据的总条数
      paginationShow: true, // 控制分页的显示隐藏达到刷新的效果
      //课程数据
      tableData: []
    };
  },
  //页面初次加载
  mounted: function() {
    this.selectstudent();
  },
  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.sels = val;
    },
    //点击链接跳转
    goTo(path) {
      this.$router.replace(path);
    },

    // 当页容量发生变化时触发
    sizeChange(size) {
      this.pageSize = size;
      // 重新请求数据
      this.selectstudent();
    },
    // 当页数发生变化时触发
    currentChange(num) {
      this.currentPage = num;
      // 重新请求数据
      this.selectstudent();
    },
    // 查询方法
    searchClicks() {
      this.paginationShow = false;
      this.currentChange(1);
      this.$nextTick(() => {
        this.paginationShow = true;
        this.selectstudent();
      });
    },
    //数据列表查询方法
    selectstudent() {
      this.$axios
        .get("/AppLogin/V4", {
          params: {
            page: this.currentPage,
            pageSize: this.pageSize,
            st_name: this.name,
            St_Phone: this.phone,
            St_Card: this.card
          }
        })
        .then(json => {
          if (json.data == "logout") {
            this.$message({
              type: "info",
              message: "您的登录信息已失效，请重新登录！"
            });
            this.$router.push("/login");
          } else {
            this.tableData = JSON.parse(json.data.stulist);
            this.total = JSON.parse(json.data.totalpage);
          }
        });
    },
    //编辑
    handleEdit(index, row) {    
      var id = row.St_id;
      this.$router.push({ name: "studentinfoedit", params: { id } });
    }
  },
  computed: {
    totalNum() {
      return this.total;
    }
  },
  watch: {
    // 监听总条数,每次查询将当前页置为 1
    totalNum(val) {
      if (val == (this.currentPage - 1) * this.pageSize && val != 0) {
        this.currentPage -= 1;
        this.selectstudent(this);
      }
    }
  }
};
</script>


<style scoped>
.locsty {
  font-size: 16px;
  font-family: "Microsoft YaHei";
}
.editsty {
  padding: 3px;
  font-size: large;
}
.iconsty {
  color: #53b9fe;
  font-size: 22px;
}
.headstyle {
  border-bottom: 2px solid #e5e5e5;
  padding-bottom: 20px;
}
.contentstyle {
  text-align: center;
  width: 90%;
  padding: 40px;
}
.selectsty {
  width: 160px;
}
/* 点击新建子级 */
.bulitContent {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 100%;
  z-index: 10000;
}
.bulitBg {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  /* background-color:#d9d9d9; */
  background-color: #7f7f7f;
  /* rgba(217,217,217,0.x) */
  z-index: -10;
  opacity: 0.5;
}
.bulitContentDetail {
  background: #ffffff;
  width: 600px;
  height: 520px;
  margin: 0 auto;
  margin-top: 13%;
}
.bulitTitle {
  height: 40px;
  background: #e1e5f4;
  line-height: 40px;
  font-size: 18px;
  color: gray;
  padding: 0 10px;
  letter-spacing: 2px;
}
.bulitTitle span {
  margin-right: 70%;
}
.close {
  cursor: pointer;
}
.trainName,
.courseName {
  font-size: 20px;
  margin-top: 20px;
  text-align: left;
  padding-left: 20px;
}

.btnSure {
  width: 80px;
  background: #527bf1;
  cursor: pointer;
  padding: 6px 10px;
  color: white;
  margin-left: 260px;
}

.tableContent {
  text-align: center;
  margin: 30px;
  height: 300px;
  /*overflow-y:scroll;  */
}
.tableContent table {
  width: 100%;

  text-align: center;
  margin: auto;
  border: 1px solid #e5e5e5;
  margin-bottom: 25px;
  border-spacing: 0;
  border-collapse: collapse;
}
.tableContent table tr th {
  background: #e6f3f8;
  border: 1px solid #e5e5e5;
  height: 30px;
}
.tableContent table tr td {
  border: 1px solid #ffffff;
  height: 50px;
  font-size: 14px;
}
.tableContent table tr th input {
  vertical-align: middle;
}
</style>

